import React, { useState, useEffect } from 'react';
import { Modal, Button, Skeleton, Image, message, Upload, Row, Col } from 'antd'
import { UploadOutlined, LoadingOutlined, PlusOutlined } from '@ant-design/icons';
import { ProFormText, ProForm, ProFormDatePicker, ProFormDateTimePicker, ProFormSelect, ProFormTextArea, ProFormUploadButton, ProFormCascader } from '@ant-design/pro-components';
import type { UploadChangeParam } from 'antd/es/upload';
import type { RcFile, UploadFile, UploadProps } from 'antd/es/upload/interface';
import { information } from '@/utils/rules';
import Utils from 'fr-util/utils';
import type { EditModalProps } from '../data';

// import { reqAddActAnswer, reqUpdateActAnswer } from '@/services/firstConsultation';

import {
  addCreatePatient,
  addUpdatePatient,
  getPatientDetail,
  getOrganizeList,
  getOrganizeCreate,
  getOrganizeUpdate
} from '@/services/register';

const TeamEditModal: React.FC<EditModalProps> = ({ row, isOpen, handleModal, actionRef }) => {
  const title = row?.id ? "修改" : "创建团体账号"
  const [formObj] = ProForm.useForm()
  const [initialValues, setinitialValues] = useState<any>(null)

  const handleAdd = async (params: any) => {
    const res = await getOrganizeCreate({ ...params })
    if (res?.resultCode === "00000000") {
      message.success(res?.message)
      // actionRef?.current.reload()
      handleModal(false)
    } else {
      message.error(res?.message)
    }
  }

  const handleEditor = async (params: any) => {
    // const res = await reqUpdateActAnswer({ ...params, id: row?.id })
    // if (res.code == 200) {
    //   message.success(res?.message)
    //   actionRef?.current.reload()
    //   handleModal(false)
    // } else {
    //   message.error(res?.message)
    // }
  }

  useEffect(() => {
    if (row?.id) {
      let { id, phoneNumber, answerData, actId } = row

      setinitialValues({
        id, phoneNumber, answerData, actId
      })
    }

    //handleActIdData({});
  }, [])




  return (
    <Modal width={500} title={title} open={isOpen} onCancel={() => handleModal(false)} footer={null} destroyOnClose={true}>
      {
        initialValues === null && row?.id ? <Skeleton active paragraph={{ rows: 6 }} /> :
          <ProForm
            form={formObj}
            initialValues={initialValues}
            onFinish={(values): Promise<any> => row?.id ? handleEditor(values) : handleAdd(values)}>
            <Row gutter={24}>
              <Col span={24}>
                <ProFormText /* name="ty_organize_id" */ label="编码" placeholder="系统生成" disabled />
              </Col>
              <Col span={24}>
                <ProFormText name="name" label="姓名" placeholder="请输入姓名" />
              </Col>
              <Col span={24}>
                <ProFormText
                  name="phoneNum"
                  label="手机号"
                  fieldProps={{
                    showCount: true,
                    maxLength: 11,
                  }}
                  rules={[
                    { required: true, message: '请输入手机号' },
                    { pattern: /^[0-9]{11}$/, message: '请输入正确的手机号' }
                  ]}
                  placeholder="请输入手机号"
                />
              </Col>
            </Row>
          </ProForm>
      }
    </Modal >
  );
};
export { TeamEditModal }

